﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb">
    <li><a href="/Home.html">Home</a></li>
    <li><a href="/WebApp/WebApi"> Sanelib WebApp</a></li>
    <li class="active">File Metadata Upload</li>
</ol>
        
            
            <div id="introduction">
                <h1 class="text-left">ControllerApis</h1>
                <h4>FileMetadataUploadController</h4>
                <p>In this FileMetadataUploadController is to done to the metadata about the Uploaded file like a filename , filesize , DateTime , etc.</p>
            </div>
            <div id="start">
                <h3>Class Inherited : SmartApiController</h3>
                <table class="table-condensed table-striped">
                    <tr>
                        <th>Constructor</th>
                        <th>Parameters</th>
                    </tr>
                    <tr>
                        <td class="table-bordered">IUserSession</td>
                        <td class="table-bordered">IMappingEngine</td>
                    </tr>
                </table>
                <p>Where, Parameters Local Variable are assigned to a Instance Variable form the <b>base</b> of <a href="/WebApp/SmartApi" class="btn-link">SmartApiController</a></p>
                <ol id="method">
                    <li>
                        In this to the only to the post of the FileMetadata of the method with return type is to the HttpResponseMessage
                        <pre><code>
public HttpResponseMessage Post([FromUri]FileDetail form)
{....}
</code></pre>
                        <p>
                            Where,<b>[FromUri] </b>using namespace is the System.Web.Http.FromUriAttribute and the Attribute that specifies that an action parameter comes from the URI of incoming requests of <b>HttpRequestMessage</b><br />
                            and <b>FileDetail</b> is the Model and the reference to the FilDetail for the file MetaDate Variable to defined in the <b>FileDetail.cs</b>
                        </p>
                        <p>In the post method first to set the value of the all FileDetail MetaData Values like,</p>
                        <pre><code>
var fileToUpload = new FileDetail
{
    FileId = GuidComb.New(),
    BlocksCount = form.BlocksCount,
    FileName = form.FileName,
    FileSize = form.FileSize,
    FileType = Path.GetExtension(form.FileName),
    FileHashCode = form.FileHashCode,
    BlockBlob = new byte[form.FileSize],
    StartTime = DateTime.Now,
    IsUploadCompleted = false,
    UploadStatusMessage = string.Empty,
    FileKey = "CurrentFile" + form.FileIndex,
    FileIndex = form.FileIndex
}; 
</code></pre>
                        <p>Here,the GuidComb is the generate the automatically FileId of 32bits and set the other value</p>
                        <p>After Set the value then the Upload the file</p>
                        <pre><code>
fileToUpload.FilePath = Globals.DownloadFolder + fileToUpload.FileId + "//";
var session = HttpContext.Current.Session;
session.Add(fileToUpload.FileKey, fileToUpload);            
</code></pre>
                        <p>
                            here, the <b>
                                Global
                            </b> is the .cs file stored in the Sanelib Library where to defined the all root directory and the create new direcory if necessary.
                            also it is a create directory for the RootFolder,LogFolder,ConfigFolder,ReportFolder, DownloadFolder<br />
                            <b>HttpContext</b> is the derived the namespace from the <b>"System.Web.HttpContext"</b> used for the user current user session.<br />
                            and after the add this file in to the current user session.<br />
                        </p>
                        <p>After the MetaData value is to set to the command of the AddRecieveFileMetaData and also validate the all Fields and return true if not the validation mismatch</p>
                        <pre><code>
var command = new AddReceiveFileMetaData
{
    Id = fileToUpload.FileId,
    FileName = form.FileName,
    FileSize = form.FileSize,
    FileType = Path.GetExtension(form.FileName),
    FilePath = fileToUpload.FilePath,
    FileHashCode = form.FileHashCode
};
ExecuteCommand(command);
return Content(new { success = true, index = fileToUpload.FileIndex });
</code></pre>
                        <p>here, After the set All the Fields from the comman commands to execute a ExecuteCommand from the <a href="./SmartApiController.html" class="btn-link">SmartApiController</a></p><br />
                        and also return content to the <a href="./SmartApiController.html" class="btn-link">SmartApiController</a>
                    </li>

                </ol>
            </div>
     